<?php
include 'config.php';

session_start();

if (!session_is_registered("myusername"))
{
	echo "Please log out and log back in.";
}

?>
	        <form id="faultyOccamPortForm" action="" method="GET">
                <table>
                        <tr><td>Blade:</td><td><select class="input" id="commandIP" name="ip">
				<?php
					$result = mysql_query("SELECT * FROM devices WHERE device_type != '6640' AND device_type != '6640 01' AND device_type != '6450' AND device_type != '6660 03'");
					
					while ( $row = mysql_fetch_array($result))
					{
						$ip_address = $row['device_ip'];
						$hostname = $row['device_name'];
						$device_type = $row['device_type'];

						$port_result = mysql_query("SELECT * FROM device_types WHERE device_type_id = '$device_type'");
						$port_count = mysql_fetch_array($port_result);
						$port_count = $port_count['device_dsl_ports'];						

						//TODO:  Show hostname or IP based on users option in profile
						if ($_SESSION['host_or_ip'] == "ip") {
							echo "<option value=\"$ip_address\">$ip_address</option>\n";
						}
						else {
							echo "<option value=\"$ip_address\">$hostname</option>\n";
						}
					}
				?>
			</select></td></tr>
			<tr><td>Port:</td><td id="ports"><select class="input" id="commandPort" name="port">
				<?php
					//TODO:  Have port total grabbed from DB based on device type.
					$port = 1;
					$port_total = 48;				
					
					echo "<option value=\"\"></option>\n";
					while ( $port <= $port_total )
					{
						echo "<option value=\"$port\">$port</option>\n";
						$port = $port+1;
					}
				?>
			</select><div><a id="runMLTTest" href="#">MLT Test</a></div></td></tr>
	                <tr><td valign="top">Problem Description:</td><td><textarea id="problemDescription" rows="30" cols="50"></textarea></td></tr>        
			<tr><td></td><td><input type="button" id="commandSubmit" value="Send!" onClick="MochaUI.notification('Please Wait...')"/><input type="reset" value="cancel"/></td></tr>

                </table>
		</form>
<script type="text/javascript">

        $('commandSubmit').addEvent('click', function(e){
		MochaUI.notification('Device Submitted');
                var url = 'pages/query.php?';
		url=url+'ip='+$('commandIP').value;
		url=url+'&port='+$('commandPort').value;
		url=url+'&problemDescription='+$('problemDescription').value;
		url=url+'&cmd=faultyOccamPort';
		url=url+'&nocache='+Math.random();
		MochaUI.updateContent({
			'element': $('panel1'),
			'loadMethod': 'xhr',
			'url': url,
			'title': 'Command Response',
			'padding': { top: 8, right: 8, bottom: 8, left: 8 }
		});
        	showSpinner();
	});

	$('runMLTTest').addEvent('click', function(e){
		MochaUI.notification('Run MLT Test');
	});

	$('commandIP').addEvent('change', function(e){
		if ($('commandPort').value != ""){ 
			var url = 'pages/blade_info.php?';
			url=url+'ip='+$('commandIP').value;
			url=url+'&port='+$('commandPort').value;
			url=url+'&cmd=modem_status';
			url=url+'&nocache='+Math.random();
			MochaUI.updateContent({
				'element': $('panel2'),
				'loadMethod': 'xhr',
				'url': url,
				'title': 'Port Information',
				'padding': { top: 8, right: 8, bottom: 8, left: 8 }
			});
			showSpinner();
		}
	});

	$('commandPort').addEvent('change', function(e){
		var url = 'pages/blade_info.php?';
		url=url+'ip='+$('commandIP').value;
		url=url+'&port='+$('commandPort').value;
		url=url+'&cmd=modem_status';
		url=url+'&nocache='+Math.random();
		MochaUI.updateContent({
			'element': $('panel2'),
			'loadMethod': 'xhr',
			'url': url,
			'title': 'Port Information',
			'padding': { top: 8, right: 8, bottom: 8, left: 8 }
		});
		showSpinner();
	});

</script>
